package com.mxx.common.generator.convert;

import com.mxx.common.generator.EntityField;
import com.mysql.cj.MysqlType;
import org.apache.ibatis.type.JdbcType;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

;

public class LocalDateTimeTypeConvert implements TypeConvert {
    public static final LocalDateTimeTypeConvert INSTANCE = new LocalDateTimeTypeConvert();

    private LocalDateTimeTypeConvert() {
    }

    @Override
    public boolean convert(EntityField entityField) {
        MysqlType mysqlType = entityField.getMysqlType();
        if (mysqlType.getJdbcType() == JdbcType.TIMESTAMP.TYPE_CODE) {
            entityField.setFieldClass(LocalDateTime.class);
            return true;
        } else if (mysqlType.getJdbcType() == JdbcType.TIMESTAMP_WITH_TIMEZONE.TYPE_CODE) {
            entityField.setFieldClass(LocalDateTime.class);
            return true;
        } else if (mysqlType.getJdbcType() == JdbcType.DATE.TYPE_CODE) {
            entityField.setFieldClass(LocalDate.class);
            return true;
        } else if (mysqlType.getJdbcType() == JdbcType.TIME.TYPE_CODE) {
            entityField.setFieldClass(LocalTime.class);
            return true;
        } else if (mysqlType.getJdbcType() == JdbcType.DATETIMEOFFSET.TYPE_CODE) {
            entityField.setFieldClass(LocalDateTime.class);
            return true;
        }
        return false;

    }
}
